package com.example.student.service.impl;

import com.example.student.mapper.ScoreMapper;
import com.example.student.pojo.PageBean;
import com.example.student.pojo.Score;
import com.example.student.pojo.Stu;
import com.example.student.service.ScoreService;
import com.example.student.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ScoreServiceImpl implements ScoreService {
    @Autowired
    ScoreMapper scoreMapper;
    @Override
    public List<Score> list() {
        return scoreMapper.list();
    }

    @Override
    public void delete(Integer id) {
        scoreMapper.deleteById(id);
    }

    public Score getByID(Integer id) {
        Score score = scoreMapper.getByID(id);
        return score;
    }

    @Override
    public void update(Score score) {
        score.setUpdateTime(LocalDateTime.now());
        score.setTotal(score.getChinese()+score.getMath()+score.getEnglish()+score.getJava()+score.getSports());
        scoreMapper.update(score);

    }

    @Override
    public PageBean page(Integer page, Integer pageSize) {
        System.out.println(page);
        System.out.println(pageSize);

        long count=scoreMapper.count();
        Integer start =(page-1)*pageSize;
        List<Score> list=scoreMapper.page(start,pageSize);

        PageBean pageBean=new PageBean(count,list);
        return pageBean;
    }

    @Override
    public PageBean rankPage(Integer page, Integer pageSize) {
        System.out.println(page);
        System.out.println(pageSize);

        long count=scoreMapper.count();
        Integer start =(page-1)*pageSize;
        List<Score> list=scoreMapper.rankPage(start,pageSize);

        PageBean pageBean=new PageBean(count,list);
        return pageBean;
    }

    @Override
    public PageBean pages(Integer page, Integer pageSize, Integer studentId,String name) {
        System.out.println(page);
        System.out.println(pageSize);

        long count = scoreMapper.counts(studentId, name);
        Integer start =(page-1)*pageSize;
        List<Score> list=scoreMapper.pages(start,pageSize,studentId,name);
        PageBean pageBean=new PageBean(count,list);
        return pageBean;
    }

    @Override
    public PageBean classPage(Integer page, Integer pageSize, Integer deptId) {
        long count = scoreMapper.classCounts(deptId);
        Integer start =(page-1)*pageSize;
        List<Score> list=scoreMapper.classPages(start,pageSize,deptId);

        PageBean pageBean=new PageBean(count,list);
        return pageBean;
    }
}

